<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>爬数据</title>
</head>
<body>
    <input type="text" class="in">
    <ul class="container">

    </ul>
    <script>
        let inputEle = document.querySelector(".in");
        let ulEle = document.querySelector(".container");
        function jsonp_0(res){
            let arr = res['s'];
            // console.log(res);
            ulEle.innerHTML = '' ; 
            arr.forEach(item => {
                let liEle = document.createElement("li");
                liEle.innerHTML = item ;
                ulEle.appendChild(liEle);
            });
        }
        inputEle.oninput = function (){
            let val = this.value;
            // console.log(val);
            if( val == '' || val == null ){
                ulEle.innerHTML = '' ;
            } else {
                let s = document.createElement("script");
                s.src = `https://suggestion.baidu.com/su?wd=${val}&cb=jsonp_0` ;
                document.head.appendChild(s);
            }
        }
    </script>
</body>
</html>